package jm.demo.proxy.cglib.immutable;

import java.util.Map;

import net.sf.cglib.beans.ImmutableBean;

import org.springframework.util.AntPathMatcher;
import org.springframework.util.StopWatch;

import com.sun.org.apache.bcel.internal.generic.IMUL;

public class ImmutableBeanPerf {


    public static void testPerf() {
        StopWatch stopWatch = new StopWatch();
        
        AntPathMatcher matcher = new AntPathMatcher();
        
        AntPathMatcher immutable_matcher = (AntPathMatcher)ImmutableBean.create(new AntPathMatcher());
        String pattern = "/main/src/**/*.java";
        String path = "/main/src/java/a.java";
        
        long counter = 1000;

        stopWatch.start("preheat - " + counter);
        
        for(int i = 0; i < counter; i++) {
            matcher.match(pattern, path);
            immutable_matcher.match(pattern, path);
        }
        stopWatch.stop();
        
        counter = 1000000;
        stopWatch.start("immutable - " + counter);
        for(int i = 0; i < counter; i++) {
            immutable_matcher.match(pattern, path);
        }
        stopWatch.stop();
        
        counter = 1000000;
        stopWatch.start("mutable - " + counter);
        for(int i = 0; i < counter; i++) {
            matcher.match(pattern, path);
        }
        stopWatch.stop();
        
        System.out.println(stopWatch.prettyPrint());
        

    }
    
    public static void testPickupWord() {
        AntPathMatcher matcher = new AntPathMatcher();
        
        
        Map<String, String> variables = matcher.extractUriTemplateVariables("find{entity}By{condition}", "findUserDetailById");
        System.out.println(variables);
        
        String result = matcher.extractPathWithinPattern("find*By", "findUserDetailById");
        System.out.println(result);
    }
    
    public static void main(String[] args) {
        testPickupWord();

    }
}
